package com.briup.shopadmin.service.impl;

import com.briup.shopadmin.common.GlobalException;
import com.briup.shopadmin.common.bean.User;
import com.briup.shopadmin.dao.IUserDao;
import com.briup.shopadmin.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    IUserDao userDao;

    @Override
    public Page<User> findUserInfo(String username, Integer pageNum, Integer pageSize) {
        if (pageNum < 1 || pageSize < 1) {
            throw new GlobalException(52001, "分页参数异常");
        }
        PageRequest request = PageRequest.of(pageNum-1, pageSize);
        Page<User> page = userDao.findByLoginNameContaining(username, request);
        return page;
    }

    @Override
    @Transactional
    public void disable(long id) {
        userDao.disable(id);
    }

    @Override
    @Transactional
    public void enable(long id) {
        userDao.enable(id);
    }
}